/*
 * File:   10047.cpp
 * Author: xerxes
 *
 * Created on September 17, 2011, 9:57 AM
 *
 * I have not failed, I have just found 10000 ways that won't work.
 */

#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define VI vector< int >
#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define fo(i,st,ed) for(int i = st ; i < ed ; ++i )
#define foE(i,st,ed) for(int i = st ; i <= ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )

inline void wait(double seconds) {
    double endtime = clock()+(seconds * CLOCKS_PER_SEC);
    while (clock() < endtime) {
        ;
    }
}
//         N  E  S  W
//         0  1  2  3
int mr[] = {-1, +0, +1, +0};
int mc[] = {+0, +1, +0, -1};

int d1[] = {1, 0, 1, 0};
int d2[] = {3, 2, 3, 2};

//          G B R B W
//          0,1,2,3,4
int nSeg[] = {1, 2, 3, 4, 0};



char grid[30][30];
int cost[30][30][4][5];
int cases;
int R, C;

inline void Read() {
    getchar();

    fo(i, 0, R) {

        fo(j, 0, C) {
            grid[i][j] = getchar();

            fo(k, 0, 4) {

                fo(l, 0, 5) {
                    cost[i][j][k][l] = (int) 1023456789;
                }
            }
        }
        getchar();
    }
}

struct NODE {
    int r, c, dir, seg;

    NODE(int a, int b, int c, int d) :
    r(a), c(b), dir(c), seg(d) {
        ;
    }
};

inline void bfs(int sr, int sc) {
    queue< NODE > q;

    q.push(NODE(sr, sc, 0, 0)); // starting direction is always north with green touching ground
    cost[sr][sc][0][0] = 0;


    while (q.empty() == false) {
        int r = q.front().r;
        int c = q.front().c;
        int d = q.front().dir;
        int seg = q.front().seg;
        int ccost = cost[r][c][d][seg];

        q.pop();
        //samne agay gelam
        int tr = mr[d] + r;
        int tc = mc[d] + c;
        int newSeg = nSeg[ seg ];

        if (tr >= 0 && tc >= 0 && tr < R && tc < C && grid[tr][tc] != '#') {
            if (ccost + 1 < cost[tr][tc][d][newSeg]) {
                q.push(NODE(tr, tc, d, newSeg));
                cost[tr][tc][d][newSeg] = ccost + 1;
            }
        }


        //direction change korlam
        int _d1 = d1[d];
        int _d2 = d2[d];
        if (ccost + 1 < cost[r][c][_d1][seg]) {
            q.push(NODE(r, c, _d1, seg));
            cost[r][c][_d1][seg] = ccost + 1;
        }
        if (ccost + 1 < cost[r][c][_d2][seg]) {
            q.push(NODE(r, c, _d2, seg));
            cost[r][c][_d2][seg] = ccost + 1;
        }
    }
}

inline void Proc() {

    fo(i, 0, R) {

        fo(j, 0, C) {
            if (grid[i][j] == 'S') {
                bfs(i, j);
                goto L;
            }
        }
    }

L:
    fo(i, 0, R) {

        fo(j, 0, C) {
            if (grid[i][j] == 'T') {
                int a = cost[i][j][0][0];
                int b = cost[i][j][1][0];
                int c = cost[i][j][2][0];
                int d = cost[i][j][3][0];
                int e = min(a, min(b, min(c, d)));
                if (e >= (int) 1023456789) {
                    printf("Case #%d\ndestination not reachable\n", cases);
                } else {
                    printf("Case #%d\nminimum time = %d sec\n", cases, e);
                }
                return;
            }
        }
    }

}

int main() {
#ifndef ONLINE_JUDGE
    freopen("in", "rt", stdin);
#endif
    cases = 1;
    for (; scanf("%d %d", &R, &C) == 2; ++cases) {
        if (R == 0 && C == 0)break;
        Read();
        if (cases != 1) {
            printf("\n");
        }
        Proc();
    }

    return 0;
}


